package com.whw.fy.controller;


import com.whw.fy.entity.Message;
import com.whw.fy.entity.ParentComm;
import com.whw.fy.service.ParentCommService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@Api(tags = "家长沟通模块")
@RestController
@RequestMapping("/api/parentcomm")
public class ParentCommController {

    @Resource
    ParentCommService parentCommService;

    @ApiOperation(value = "添加家长沟通记录")
    @PostMapping("/insert")
    public Message insert(ParentComm parentComm)throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (parentComm.getPCreattimeToString()!=null)
            parentComm.setPCreattime(simpleDateFormat.parse(parentComm.getPCreattimeToString()));
        return parentCommService.insertSelective(parentComm);
    }

    @ApiOperation(value = "删除家长沟通记录")
    @DeleteMapping("/")
    public Message delete(int parentCommId) {
        return parentCommService.deleteByPrimaryKey(parentCommId);
    }

    @ApiOperation(value = "修改家长沟通记录")
    @PutMapping("/")
    public Message update(ParentComm parentComm){
        return parentCommService.updateByPrimaryKeySelective(parentComm);
    }

    @ApiOperation(value = "根据沟通记录id查找家长沟通记录")
    @GetMapping("/select")
    public Message selectByPrimaryKey(int parentCommId){
        return parentCommService.selectByPrimaryKey(parentCommId);
    }

    @ApiOperation(value = "获得所有家长沟通记录")
    @GetMapping("/all")
    public Message selectAll(){
        return parentCommService.selectAll();
    }



}
